public class 字符串转换整数 {
    

    public static void main(String[] args) {
        
        System.out.println(myAtoi("+11e530408314"));

    }

    public static int myAtoi(String s) {
        
        s = s.trim();

        if("".equals(s)) return 0;

        StringBuilder builder = new StringBuilder();

        boolean minZreo = false;

        char first = s.charAt(0);
        if(first != '+' && first != '-' && !Character.isDigit(first)){

            return 0;
        } else if(!Character.isDigit(first) && 1 == s.length()){

            return 0;
        }

        if(first == '-'){
            minZreo = true;
            builder.append(first);
        } else if(first == '+'){
            builder.append("");
            minZreo = false;
        } else {
            builder.append(first);
            minZreo = false;
        }

        for(int i=1; i<s.length(); i++){

            char c = s.charAt(i);
            if(Character.isDigit(c)){
                builder.append(c);

            }else{

                if((first == '-' && builder.toString().length() > 1) || (first != '-' && builder.toString().length() >= 1) || c == '.'){
                    return parseInt(builder.toString(), minZreo);
                }else{
                    return 0;
                }
            }
        }



        return parseInt(builder.toString(), minZreo);
    }

    private static int parseInt(String str, boolean minZreo){


        try{


            return Integer.parseInt(str);

        }catch(Exception e){

            if(minZreo){

                //小于 0

                return Integer.MIN_VALUE;
            } else {

                return Integer.MAX_VALUE;
            }

        }

    }
}
